import time

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

browser = webdriver.Chrome()

browser.get('https://www.12306.cn/index/')

# ��λ��������
id_from_word = 'fromStationText'
locator_from = (By.ID, id_from_word)
wait = WebDriverWait(browser, 10).until(EC.presence_of_element_located(locator_from))

# ��������
input1 = browser.find_element(By.ID, id_from_word)
input1.clear()
input1.send_keys("厦门北")
browser.find_element(By.ID, 'citem_0').click()

# ��λ��Ŀ�ĵ�
id_to_word = 'toStationText'
locator_to = (By.ID, id_to_word)
wait = WebDriverWait(browser, 10).until(EC.presence_of_element_located(locator_to))

# ��������
input2 = browser.find_element(By.ID, id_to_word)
input2.clear()
input2.send_keys("黄山北")
browser.find_element(By.ID, 'citem_0').click()


# ��λ������
id_date_word = "train_date"
input3 = browser.find_element(By.ID, id_date_word)
input3.clear()
input3.send_keys("2024-06-08")

# 点击进行搜索
# id_button = 'search_one'
# locator_button = (By.ID, id_button)
# wait = WebDriverWait(browser, 10).until(EC.element_to_be_clickable(locator_button))
# //*[@id="search_one"]
btn = browser.find_element(By.XPATH, '//*[@id="search_one"]')
btn.click()

time.sleep(10)

browser.close()